package cn.micai.base.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * 描述：并发类容器之Queue
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/2/22 16:23
 */
public class UseQueue3 {


    public static void main(String [] args) {
        try {
            // 该队列可以是无界队列也可以是有界队列，不指定长度便是无界队列，指定长度便是有界队列
            LinkedBlockingQueue<String> linkedBlockingQueue = new LinkedBlockingQueue<>();
            linkedBlockingQueue.offer("a");
            linkedBlockingQueue.offer("b");
            linkedBlockingQueue.offer("c");
            linkedBlockingQueue.offer("d");
            linkedBlockingQueue.offer("e");
            linkedBlockingQueue.offer("f");

            List<String> list = new ArrayList<>();
            System.out.println(linkedBlockingQueue.drainTo(list, 3));
            System.out.println(list.size());

            for (String str : list) {
                System.out.println(str);
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
